<template>
	<view class="page">
		<view>
			<radio-group>
				<view class="radio-item" 
				v-for="(item, index) in items" 
				:key="item.value"
				@click="clickRadio(index,item.value)"
				>
					<span>{{item.value}}x{{item.value}}格子 积分：{{item.value}}分</span>
					<radio disabled :value="item.value" :checked="index === current" />
				</view>
			</radio-group>
		</view>
		
		<button type="primary" @click="toPk">设置完成</button>
		
	</view>
</template>
<script>
	
	var _self
	import utils from '../../common/util.js'
	
	export default {
		data() {
			return {
				items: [{
						value: '8',
						bombNumber: '10',
					},
					{
						value: '10',
						bombNumber: '16',
					},
					{
						value: '12',
						bombNumber: '23',
					},
					{
						value: '15',
						bombNumber: '40',
					},
					{
						value: '18',
						bombNumber: '52',
					},
					{
						value: '20',
						bombNumber: '64',
					},
					{
						value: '25',
						bombNumber: '100',
					}
				],
				current: 0,
				opponet: {},
			}
		},
		onShow() {
			//打开webSocket
			// if(!_self.$store.state.start_timeId){
			// 	utils.connectSocketInit()
			// }
		},
		onLoad(data) {
			console.log(uni.getStorageSync("saolei_userInfo"))
			if(uni.getStorageSync("saolei_userInfo").count < 8){
				uni.showModal({
					showCancel:false,
					title:"提示",
					content:"积分不足8分,请先通过单人模式获得积分哦(・(ｪ)・)",
					success: function (res) {
						if (res.confirm) {
							uni.navigateBack({
								delta:1
							})
						}
					}
				})
			}
			
			_self = this
			// 获取挑战对手资料
			uni.request({
				url: utils.basicUrl+"/saoleiUser/"+data.opponetId,
				method: "GET",
				data: {},
				success: function(res) {
					if(res.data.code === 20000){
						_self.opponet = res.data.data
						if(_self.opponet.count < 8){
							uni.showModal({
								showCancel:false,
								title:"提示",
								content:"这人积分不足8分，这次就饶过他吧(΄◉◞౪◟◉`)",
								success: function (res) {
									if (res.confirm) {
										uni.navigateBack({
											delta:1
										})
									}
								}
							})
						}
					}else{
						_self.utils.requestFail(res)
						// uni.showToast({
						// 	icon:"none",
						// 	title: res.data
						// })
					}
				},
				fail: () => {
					uni.showToast({
						icon:"none",
						title: '网络错误(｡・`ω´･)'
					})
				},
				complete() {
					uni.hideLoading()
				}
			})
			
			
		},
		methods: {
			clickRadio(index,value){
				if(uni.getStorageSync("saolei_userInfo").count < value){
					uni.showToast({
						icon:"none",
						title:"你的积分不够哦(｡・`ω´･)"
					})
				}else if(_self.opponet.count < value){
					uni.showToast({
						icon:"none",
						title:"对方积分不够哦，这次就饶过他吧(΄◉◞౪◟◉`)"
					})
				}else{
					this.current = index
				}
				
			},
			toPk(){
				// if(!_self.isLogin){
				// 	return
				// }
				_self.opponet.colum = this.items[this.current].value
				_self.opponet.bombNumber = this.items[this.current].bombNumber
				_self.$nextTick(function(){
					_self.$store.commit("setOpponet",_self.opponet)
					uni.navigateTo({
						url:"../pk/pk",
						animationType:"slide-in-left",
						animationDuration:400
					})
				})
			}
		}
	}
</script>

<style>
	@import url("pkSetting.css");
</style>
